/*
 * @Title: 票选优品首页
 * @Author: Jcuiweif
 * @Date:   2018-12-19
 * @Last Modified by:   Jcuiweif
 * @Last Modified time: 2018-12-24
 */
$(document).ready(function(){
    if ($(document).width()<= 450 ){
    var t = $(document).width()/10;
    $("html").css("font-size",t);
    // alert($(document).width())
    } else {
      $("html").css("font-size",45);
    }
  })
var dataInfo = {},
  template = {
    init: function() {
      Vue.use(VueLazyload, {
        preLoad: 1.3,
        error: 'https://h5.meetao.com/img/product/init.png',
        loading: 'https://h5.meetao.com/img/product/init.png',
        attempt: 1
      });
      dataInfo.init = new Vue({
        el: '#app',
        data: {
          width: document.body.offsetWidth,
          tabData: [],
          swiperData: [],
          votebannerdown:[],
          versions: versions,
          icon: {
            normal: '../img/index/shouhui.png',
            active: '../img/index/shouhong.png',
            normal1: '../img/index/gouhui.png',
            active1: '../img/index/gouhong.png',
            active2: '../img/index/myhong.png',
            normal2: '../img/index/myhui.png',
            active3: '../img/index/pthong.png',
            normal3: '../img/index/pthui.png',
          },
          playicon:'../img/playVideo.png',
          active: 0,
          activeindex:0,
          all: false, //loadOver - show
          isFx: 1,
          isDz: 0,
          page: 1,
          choose:0,
          limit: 10,
          areanone:'../img/voteGoods/area.png',
          loading1: 'https://h5.meetao.com/img/product/init.png',//whtiteeyes.png
          eyes:'../img/voteGoods/eyes.png',
          whtiteeyes:'../img/voteGoods/whtiteeyes.png',
          loading: false,
          isLoading: false,
          finished: false,
          listData: [], //商品集合
          backsource: [],
          share:{
            img:'../img/voteGoods/imgShare.png',
            noneimg: '../img/404/404.png'
          }
        },
        methods: {
          onLoad: function() {
            this.sourceagain();
          },
          onRefresh: function() { //下拉刷新
            this.listData = [];
            // this.page = 1;
            dataInfo.init.all = false;
            setTimeout(function() {
              dataInfo.init.sourceagain();
            }, 500);
          },
          sourceagain:function(){
            ajaxTemplate(addressTest + SERVICE.backsource, function(data) {
              console.log(data);
              var daTa = data.data.result;
              // dataInfo.init.backsource = data.data.result;//
              // var s = dataInfo.init.pagesource++;
              // dataInfo.init.$set(dataInfo.init,'pagesource',s);
              if (!daTa||daTa.length == 0){
                if (dataInfo.init.backsource.length ==0){
                } else {
                  dataInfo.init.all= true;
                }
                dataInfo.init.loading = false;
                dataInfo.init.isLoading = false;
                dataInfo.init.finished = true;
                // dataInfo.init.all = true;
                return;
              }
              if (data.tag == 0) {
                dataInfo.init.backsource = JSON.parse(JSON.stringify(dataInfo.init.backsource.concat(daTa)));
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished = true;
                  dataInfo.init.all = true;
                } else {
                  console.log('有数据')
                  dataInfo.init.finished = false;
                };
                
                dataInfo.init.loading = false;
                dataInfo.init.isLoading = false;
              } else {
                dataInfo.init.$toast(data.errMsg);
                if (data.errMsg == '未查询到符合条件的商品'){
                  dataInfo.init.loading1 = false;
                  dataInfo.init.isLoading1 = false;
                  dataInfo.init.all1 = true;
                  dataInfo.init.finished1 = true;
                }
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.page++,
            });
          },
          sourceagain1:function(){
           
            ajaxTemplate(addressTest + SERVICE.backsource, function(data) {
              console.log(data);
              var daTa = data.data.result;
              // dataInfo.init.backsource = data.data.result;//
              // var s = dataInfo.init.pagesource++;
              // dataInfo.init.$set(dataInfo.init,'pagesource',s);
              if (data.tag == 0) {
                console.log('werw'+daTa)
                if (!daTa||daTa.length == 0){
                  // dataInfo.init.$toast('全部加载完');
                  if (dataInfo.init.backsource.length ==0){
                    // dataInfo.init.nodata= true;
                  } else {
                    dataInfo.init.all= true;
                  }
                  dataInfo.init.loading = false;
                  dataInfo.init.isLoading = false;
                  dataInfo.init.finished = true;
                  // dataInfo.init.all = true;
                  return;
                }
                dataInfo.init.backsource = JSON.parse(JSON.stringify(daTa.concat(dataInfo.init.backsource)));
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished = true;
                  dataInfo.init.all = true;
                } else {
                  console.log('有数据')
                  dataInfo.init.finished = false;
                };
                dataInfo.init.loading = false;
                dataInfo.init.isLoading = false;
              } else {
                dataInfo.init.$toast(data.errMsg);
                if (data.errMsg == '未查询到符合条件的商品'){
                  dataInfo.init.loading1 = false;
                  dataInfo.init.isLoading1 = false;
                  dataInfo.init.all1 = true;
                  dataInfo.init.finished1 = true;
                }
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.page++,
            });
          },
          bannerJump: function(data) { //bannerJump
            if (data.linkRemark == 'product') { //商品 文章 视频 均为跳转内部地址 h5为跳转全链接地址
              jumpProductDetails(data.params);
            } else if (data.linkRemark == 'h5') {
              window.location.href = data.link;
            } else if (data.linkRemark == 'article') {

            } else if (data.linkRemark == 'video') {

            };
          },
          bannerJump2: function(data) { //bannerJump
            console.log(data)
            if (data.linkRemark == 'product') { //商品 文章 视频 均为跳转内部地址 h5为跳转全链接地址
              jumpProductDetails(data.params);
            } else if (data.linkRemark == 'h5') {
              window.location.href = data.h5JumpUrl;
            } else if (data.linkRemark == 'article') {

            } else if (data.linkRemark == 'video') {

            };
          },
          toProduct: function(data) { //toProduct
            jumpProductDetails(data);
          },
          textsource: function(index){
            var sourcegroup = dataInfo.init.backsource;
            var sourceCode = sourcegroup[index].sourceCode;
            var type = sourcegroup[index].sourceType;
            console.log(sourcegroup[index])
            ajaxTemplate(addressTest + SERVICE.sourceinfo, function(data) {
              if (data.tag == 0) {
                  var result = data.data.result;
                  // console.log('theme',result.isOnline);
                  if (result.isOnline == 1){
                    if (type == 'text'){
                      location.href = 'FPtSourceTalk.html?sourceCode='+encodeURIComponent(sourceCode)+'&sourceTitle='+encodeURIComponent(sourcegroup[index].sourceTitle)+'&id='+encodeURIComponent(sourcegroup[index].id);
                    } else if (type == 'video'){
                      location.href = 'FPtVoteVedioDetail.html?sourceCode='+encodeURIComponent(sourceCode)+'&sourceTitle='+ encodeURIComponent(sourcegroup[index].sourceTitle)+'&id='+encodeURIComponent(sourcegroup[index].id);
                    }
                  } else {
                    dataInfo.init.$toast('该活动已下线');
                    dataInfo.init.backsource = dataInfo.init.backsource.splice(index,1);
                  }
                  
              } else {
                  dataInfo.init.$toast(data.errMsg);
              };
              }, {
                  sourceCode:sourceCode,
              });
            
            
          },
          tabJump: function(data) {
            location.href = "../html/productClassify.html?code=" + data.code + "&name=" + escape(data.name);
          },
          getProductDetails: function() { //获取商品数据
            ajaxTemplate(addressUrl + SERVICE.queryFxGoodsList, function(data) {
              console.log(data);
              var daTa = data.data.result;
              if (data.tag == 0) {
                dataInfo.init.listData = JSON.parse(JSON.stringify(dataInfo.init.listData.concat(daTa)));
                if (daTa.length < dataInfo.init.limit) {
                  console.log("无数据")
                  dataInfo.init.finished = true;
                  dataInfo.init.all = true;
                } else {
                  console.log('有数据')
                  dataInfo.init.finished = false;
                };
                dataInfo.init.loading = false;
                dataInfo.init.isLoading = false;
                //					是否要有秒杀
                //					daTa.forEach(function(item, index) {
                //						if(item.isKill !== 0) {
                //							dataInfo.init.listData.push(item);
                //						};
                //					});
                //					setTimeout(function() {
                //						var tid = "index" + (daTa.length - 1);
                //						$('#' + tid).ready(function() {
                //							$(".loadImgBox").addClass("rgba").hide();
                //						});
                //					}, 300);
              } else {
                dataInfo.init.$toast(data.errMsg);
              };
            }, {
              limit: dataInfo.init.limit,
              page: dataInfo.init.page++,
            });
          },
          getSource: function() {
            shareInfo.imgUrl = dataInfo.init.share.img;
            // shareInfo.stitle = '';
            ajaxTemplate(addressTest + SERVICE.backsource, function(data) {//获取溯源列表
                //   console.log(data);
                  if (data.tag == 0) {
                    dataInfo.init.tabData = data.data.result;

                  } else {
                    dataInfo.init.$toast(data.errMsg);
                  };
                }, {
                    page:dataInfo.init.page,
                    limit:dataInfo.init.limit,
                });
          },
        },
      });
      dataInfo.init.getSource();
    //   dataInfo.init.getTab();
    }
  };
template.init();

